// !@#$McCaBe-InStRuMeNtAtIoN$#@!
// Instrumented with the McCabe Java Parser
// Version: 8.1.0.1 - 20110309
// Using Path Vector Instrumentation
// Date: Sun Apr 01 2012 20:41:37
package Model;

import java.util.ArrayList;

import com.mccabe.*;


class BookingManager_c5fff935d5349eb7a7badd4406755235 {
    static java.lang.Object info[];
    static {
        info = new java.lang.Object[2];
        info[0] = new Integer(-1);
        info[1] = new String("R:\\yu\\Concordia\\SOEN 344 Design II\\Term Assignment\\Code Repo\\trunk\\Iteration 3\\ERS\\src\\Model\\BookingManager.java");
    }
}


/**
 * Manages bookings and aggregates them.
 * @author Yury Kitaev
 *
 */
public class BookingManager 
{
	private ArrayList<Booking> bookings;
	private Catalog catalog;
	
	public BookingManager(Catalog catalog)
	{
		super();
int _mcFreq_d0ab7dff90daf59d2f2d997c831899c6[] = PathVec_ERS_Iter3.getIntArray(0);
PathVec_ERS_Iter3.releaseIntArray();
PathVec_ERS_Iter3.enterConstructorWithECC(BookingManager_c5fff935d5349eb7a7badd4406755235.info,0,_mcFreq_d0ab7dff90daf59d2f2d997c831899c6,0);

		this.catalog = catalog;
		bookings = new ArrayList<Booking>();
	}

	public Booking makeBooking(Person person, int id, int seatNumber) throws Service.EventClosedException
	{
int _mcFreq_608d6ef672e3a29e0c1172960f1e76d8[] = new int[17];
PathVec_ERS_Iter3.enterMethod(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,0);

		// Find event in the catalog
		Event event = null;
		
{
boolean  MCCABE_EVENT_7 = true;
for (Event e : catalog.getEvents())
		{
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,1,0,true);

			if (
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,3,4,
PathVec_ERS_Iter3.testCondition(e.getId() == id
))
)
			{
				event = e;		
				
{
 MCCABE_EVENT_7 = false; 
break;
}

			}
		}
if ( MCCABE_EVENT_7) PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,2,0,true);

}

		
		if (
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,5,6,
PathVec_ERS_Iter3.testCondition(null == event
))

		 || 
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,7,8,
PathVec_ERS_Iter3.testCondition(EventStatus.Closed == event.getStatus()
))
)
		{
			throw new Service.EventClosedException("The event is closed.");			
		}
		
		// Find a seat
		Seat seat = null;
		if (
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,9,10,
PathVec_ERS_Iter3.testCondition(!event.getVenue().getSeats().get(seatNumber - 1).isTaken()
))
)
		{
			seat = event.getVenue().getSeats().get(seatNumber - 1);
		}
		else
		{
			// The seat was taken, take any available seat
			
{
for (Seat s : event.getVenue().getSeats())
			{
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,11,0,true);

				if (
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,13,14,
PathVec_ERS_Iter3.testCondition(!s.isTaken()
))
)
				{
					seat = s;
				}
			}
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,12,0,true);

}

		}
		if (
PathVec_ERS_Iter3.decision(BookingManager_c5fff935d5349eb7a7badd4406755235.info,1,_mcFreq_608d6ef672e3a29e0c1172960f1e76d8,15,16,
PathVec_ERS_Iter3.testCondition(null == seat
))
)
		{
			throw new Service.EventClosedException("No seats found, the event must be closed!");
		}
		
		Booking booking = new Booking(person, event, seat);
		
		bookings.add(booking);
		
		event.refreshStatus();
		
		return booking;
	}
	
	/**
	 * Gets the list of bookings made
	 * @return
	 */
	public ArrayList<Booking> getBookings() 
	{
int _mcFreq_92bf4e82dba66d3def245e4fa48f2099[] = new int[1];
PathVec_ERS_Iter3.enterMethod(BookingManager_c5fff935d5349eb7a7badd4406755235.info,2,_mcFreq_92bf4e82dba66d3def245e4fa48f2099,0);

		return bookings;
	}

	public void setBookings(ArrayList<Booking> bookings) 
	{
int _mcFreq_330281c2b5e4ce81a5ba59608dc1d349[] = new int[1];
PathVec_ERS_Iter3.enterMethod(BookingManager_c5fff935d5349eb7a7badd4406755235.info,3,_mcFreq_330281c2b5e4ce81a5ba59608dc1d349,0);

		this.bookings = bookings;
	}

	public Catalog getCatalog() 
	{
int _mcFreq_6802ce20025a7ab84b4f01def38745e5[] = new int[1];
PathVec_ERS_Iter3.enterMethod(BookingManager_c5fff935d5349eb7a7badd4406755235.info,4,_mcFreq_6802ce20025a7ab84b4f01def38745e5,0);

		return catalog;
	}

	public void setCatalog(Catalog catalog) 
	{
int _mcFreq_2e92b65c89f5e5167600171620332a69[] = new int[1];
PathVec_ERS_Iter3.enterMethod(BookingManager_c5fff935d5349eb7a7badd4406755235.info,5,_mcFreq_2e92b65c89f5e5167600171620332a69,0);

		this.catalog = catalog;
	}
}
